﻿using DGZImp.Core.Services;
using DGZImp.MdsProject.Devices.Models;
using Microsoft.AspNetCore.Hosting.Server;
using Nomad.Iot.Core;
using Nomad.Iot.Core.Net;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DGZImp.MdsProject.Devices.Base
{
    public abstract class PlcServe : IIotServe
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Ip { get; set; }
        public int Port { get; set; }

        public List<DbBlockCfgItem> DbBlocks { get; set; } = new List<DbBlockCfgItem>();
        public ConcurrentDictionary<string, byte[]> Datas { get; set; } = new ConcurrentDictionary<string, byte[]>();

        /// <summary>
        /// 读取间隔，单位ms
        /// </summary>
        public int ReadInterval { get; set; } = 300;

        /// <summary>
        /// 是否自动读取数据
        /// </summary>
        public bool IsAutoRead { get; set; } = true;

        public abstract event PlcDataReceiveHandler OnPlcDataReceive;
        public abstract event HttpDataReceiveHandler OnHttpDataReceive;
        public abstract event TcpDataReceiveHandler OnTcpDataReceive;
        public abstract event WebSocketDataReceiveHandler OnWebSocketDataReceive;

        public abstract void Dispose();
        public abstract Task StartReadingAsync();

    }

}
